﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DataAccess.Operate
{
    public class DA_Project_Confirmation_Inherit:SqlInteractionBase
    {

        /// <summary>
        /// 返回指定项目指定类型的确认书集合
        /// </summary>
        /// <param name="id">项目主键ID</param>
        /// <param name="agentID">类型ID</param>
        /// <returns></returns>
        public DataSet FindByProjectIDAndAgentID(string id, string agentID)
        {
            string sSql = "select * from t_Project_Confirmation where Project_Confirmation_CommissionID=(select Project_ProjectCommission_ID from t_Project_ProjectCommission where Project_ProjectCommission_ProjectID='" + id + "' and Project_ProjectCommission_AgentID=" + agentID + ") order by Project_Confirmation_Date asc";
            SqlCommand cmdToExecute = new SqlCommand();
            SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
            DataTable toReturn = new DataTable("t_Project_Commission");
            DataSet ds = new DataSet();

            cmdToExecute.CommandText = sSql;
            cmdToExecute.CommandType = CommandType.Text;

            try
            {
                cmdToExecute.Connection = _mainConnection;
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                adapter.Fill(ds);


            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Close();
                }

                cmdToExecute.Dispose();

                adapter.Dispose();
            }

            return ds;
        }
    }
}
